/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: happyiu
 * Date: 2021-11-14
 * Time: 9:34
 */



/*class Person {

    private String name;//实例成员变量
    private int age;
    private String sex;
    //默认构造函数 构造对象
    public Person() {
        this.name = "lalala";
        this.age = 10;
        this.sex = "男";
    }
    //带有3个参数的构造函数
    public Person(String name,int age,String sex) {
        this.name = name;
        this.age = age;
        this.sex = sex;
    }
    public void show(){
        System.out.println("name: "+name+" age: "+age+" sex: "+sex);
    }

}
public class TestDemo{
    public static void main(String[] args) {
        Person p1 = new Person();//调用不带参数的构造函数 如果程序没有提供会调用不带参数的构造函数
        p1.show();
        Person p2 = new Person("hahaha",80,"男");//调用带有3个参数的构造函数
        p2.show();
    }
}
// 执行结果
//name: lalala age: 10 sex: 男
//name: hahaha age: 80 sex: 男*/


/*class People{
    String name = "hahaha";
    int age = 10;

    public void print() {
        this.func();
        System.out.println("姓名："+name+" 年龄："+age);
    }

    public void func(){
        System.out.println("调用当前对象的func");
    }


}

public class TestDemo{
    public static void main(String[] args) {
        People people = new People();
        people.print();
    }
}*/

/*class People{
    String name;
    int age = 10;

    public People() {
        this("haha");
        //this("gege");
        System.out.println("调用了不带参数的构造方法");
    }

    public People(String name) {
        this.name = name;
        System.out.println("调用了带一个String类型参数的构造方法");
    }


}

public class TestDemo{
    public static void main(String[] args) {
        People people = new People();
    }
}*/


/*
public class TestDemo{
    public static void main(String[] args) {
        { //直接使用{}定义，普通方法块
            int x = 10 ;
            System.out.println("x1 = " +x);
        }
        int x = 100 ;
        System.out.println("x2 = " +x);
    }
}
// 执行结果
// x1 = 10
// x2 = 100*/


/*class People{
    String name;
    int age;

    static {
        //这就是静态代码块
        System.out.println("静态代码块！");
    }

    {
        //这就是实例代码块
        this.age = 99;
        System.out.println("实例代码块！");
    }

    public People() {
        System.out.println("不带参数的构造方法!");
    }

}
public class TestDemo{
    public static void main(String[] args) {
        People people1 = new People();
        System.out.println("===============");
        People people2 = new People();
    }
}*/


/*
class Person {
    private String name;
    private int age;
    public Person(String name,int age) {
        this.age = age;
        this.name = name;
    }
    public void show() {
        System.out.println("name:"+name+" " + "age:"+age);
    }

    //重写Object的toString方法
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

public class TestDemo {
    public static void main(String[] args) {
        Person person = new Person("hahaha",19);
        person.show();
        //我们发现这里打印的是一个地址的哈希值 原因：调用的是Object的toString方法
        System.out.println(person);
        System.out.println(person.toString());
    }
}
// 执行结果
//name：caocao age：19
//Person@1c168e5*/


/*class Person {
    private String name;
    private int age;
    public Person(String name,int age) {
        this.age = age;
        this.name = name;
    }
    public void show() {
        System.out.println("name:"+name+" " + "age:"+age);
    }
}
public class TestDemo {
    public static void main(String[] args) {
        new Person("haha",19).show();//通过匿名对象调用方法
    }
}*/

